package design.structure.组合;

import lombok.Data;

import java.util.List;
import java.util.Vector;

/**
 * 组合模式  30%
 */
@Data
public class Person {
    private String name;

    private List<Person> personList;

    public Person(String name) {
        this.name = name;
        this.personList = new Vector<>();
    }

    private Person add(Person e) {
        personList.add(e);
        return this;
    }

    public Person remove(Person e) {
        personList.remove(e);
        return this;
    }


    public static void main(String[] args) {
        Person person = new Person("boos");


        Person person1 = new Person("一级 人1");
        Person person2 = new Person("一级 人2");

        Person person3 = new Person("二级 人1");
        Person person4 = new Person("二级 人2");

        person.add(person1).add(person2);

        person1.add(person3);
        person2.add(person4);


        System.out.println(person.getName());
        for (Person p : person.getPersonList()) {
            System.out.println(p.getName());
            for (Person p_ : p.getPersonList()) {
                System.out.println(p_.getName());
            }
        }

    }
}
